< previous page page_510 next page >

Page 510
0510-01.jpg
Figure 23.2
You can write a VB program to act as a screen saver.
In recent years, the screen saver has almost become an art form, with everything from 3D pipes to flying toasters. However, if you want to be really creative, you can create your own screen saver. In Visual Basic, this task is actually very easy. You write the screen saver just like a normal program, but you program the events differently. For example, mouse movement stops the program. In the next section, you create a simple screen saver.
Setting Up the Main Form
Your screen saver will actually be a Standard EXE project. To begin, start a new Standard EXE project, and modify the form's designtime properties as follows:
1. Set the WindowState property to Maximized.
2. Set the BorderStyle property to None.
3. Set the BackColor property to the color black.
As you know, a screen saver ends when a user moves the mouse or presses keys on the keyboard. Add End statements to the form's MouseMove and KeyPress events as follows:
Dim nMouseCount As Integer
Private Sub Form_KeyPress(KeyAscii As Integer)
    End
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, _
 X As Single, Y As Single)
    nMouseCount = nMouseCount + 1
    If nMouseCount > 5 Then End
End Sub
Note that you use a counter so that the program does not end on the first MouseMove event. You need this counter because Windows sends a couple of MouseMove events to the program when it starts.

 
< previous page page_510 next page >